// 4.0 获取菜单数据
import axios from "../../utils/axios"

export default {
    namespaced: true,
    state() {
        return {
            specsList: [],
            specsCount:0
        }
    },
    mutations: {
        saveSpecsListMutations(state, list) {
            console.log("saveSpecsListMutations执行了")
            console.log(list)
            state.specsList = list
        },
        saveSpecsCountListMutations(state,list){
            state.specsCount = list
        }
    },
    actions: {
        getSpecsListActions({commit},pagesinfo) {
            console.log("getSpecsListActions执行了")
            axios({
                method: 'GET',
                url: '/api/specslist',
                params:pagesinfo
            }).then( response => {
                // 关联上下级菜单数据
                console.log(response)
                // let pmenus = response.list.filter(item => item.pid === 0)
                // pmenus.forEach(pitem => {
                //     pitem.children = []
                //     response.list.forEach(item => {
                //         if (item.pid === pitem.id) {
                //             pitem.children.push(item)
                //         }
                //     })
                // })

                commit('saveSpecsListMutations', response.list)
                
            })
        },
        getSpecsCountListActions({commit}){
            axios({
                method: 'GET',
                url: '/api/specscount',
            
            }).then( response => {
                // 关联上下级菜单数据
                console.log(response)
                commit('saveSpecsCountListMutations',response.list[0].total||0)
        })
      }    
    }, 
    getters: {}

   
}



